package Ep02_LinkedList._0019;

import Ep02_LinkedList.ListNode;

/**
 * @author Jimmy Zhan WORKSTATION
 * @date 2023/3/8 18:21
 * 说明： 力扣 0019删除链表的倒数第 N个节点
 * 滑动窗口：快慢指针
 *
 */

public class Mine {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        // 滑动窗口
        ListNode dummyHead = new ListNode(0, head);
        ListNode pre = dummyHead;
        ListNode cur = pre;
        while (n >= 0){
            cur = cur.next;
            n--;
        }
        while (cur != null){
            cur = cur.next;
            pre = pre.next;
        }
        pre.next = pre.next.next;

        return dummyHead.next;
    }
}
